<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="gray-bg">
    
     <div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="formId">
					<div class="select-list">
						<ul>
							<li>
								用户名：<input type="text" name="userName"/>
							</li>

							<li>
								优惠序号：<input type="text" name="yhqId"/>
							</li>

							<li class="select-time">
								<label >状态：</label>
								<select  name="useState" id="yhqState" onchange="$.table.search()" >
									<option ></option>
									<option value="0">已使用</option>
									<option value="1">正常有效</option>
									<option value="2">已过期</option>
									<option value="3">已冻结</option>
								</select>
							</li>
<!--							<li>
								使用状态 0 已使用 1 正常有效 2 过期 3 已冻结：<input type="text" name="useState"/>
							</li>-->

<!--							<li>
								使用时间：<input type="text" name="useDate"/>
							</li>-->
							<li class="select-time">
								<label>使用时间： </label>
								<input type="text" class="time-input" id="startTime" placeholder="起始时间" name="startTime"/>
								<span>-</span>
								<input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endTime"/>
							</li>

<!--							<li>
								删除标记：<input type="text" name="delFlag"/>
							</li>-->

							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			
	        <div class="btn-group-sm hidden-xs" id="toolbar" role="group">
<!--				<a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="gxgw_modules:yhqOwner:add">
					<i class="fa fa-plus"></i> 添加
				</a>
				<a class="btn btn-primary btn-edit disabled" onclick="$.operate.edit()" shiro:hasPermission="gxgw_modules:yhqOwner:edit">
					<i class="fa fa-edit"></i> 修改
				</a>-->
				<a class="btn btn-danger btn-del btn-del disabled" onclick="$.operate.removeAll()" shiro:hasPermission="gxgw_modules:yhqOwner:remove">
					<i class="fa fa-remove"></i> 删除
				</a>
				<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gxgw_modules:yhqOwner:export">
						<i class="fa fa-download"></i> 导出
				 </a>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table" data-mobile-responsive="true"></table>
			</div>
		</div>
	</div>
    <div th:include="include :: footer"></div>
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('gxgw_modules:yhqOwner:edit')}]];
        var removeFlag = [[${@permission.hasPermi('gxgw_modules:yhqOwner:remove')}]];
        var prefix = ctx + "gxgw_modules/yhqOwner";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
				exportUrl: prefix + "/export",
                modalName: "用户及其优惠券",
				search: false,
		        showExport: true,
                columns: [{
		            checkbox: true
		        },
				{
					field : 'ownerId', 
					title : '序号',
					visible: false
				},
				{
					field : 'userId',
					title : '用户序号',
					visible: false
				},
				{
					field : 'userName',
					title : '用户名',
					sortable: true
				},
				{
					field : 'yhqId', 
					title : '优惠券编号',
					sortable: true
				},
				{
					field : 'useState', 
					title : '使用状态',
					sortable: true,
					formatter: function (value) {
						switch (value) {
							case 0:
								return '已使用'
							case 1:
								return '正常有效'
							case 2:
								return '已过期'
							case 3:
								return '冻结'

						}
					}
				},
				{
					field : 'useDate', 
					title : '使用时间',
					sortable: true
				},
/*				{
					field : 'delFlag', 
					title : '删除标记',
					sortable: true
				},*/
				{
					visible: editFlag == 'hidden' ? false : true,
					title: '冻结',
					align: 'center',
					formatter: function (value, row, index) {
						return statusTools(row);
					}
				},

		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	var actions = [];
		            	// actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="#" onclick="$.operate.edit(\'' + row.ownerId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.ownerId + '\')"><i class="fa fa-remove"></i>删除</a>');
						return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });


		/* 状态显示 */
		function statusTools(row) {
			if (row.useState != 3) {
				return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.ownerId + '\')"></i> ';
			} else {
				return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.ownerId + '\')"></i> ';
			}
		}

		/* 冻结 */
		function disable(ownerId) {
			$.modal.confirm("确认要恢复此用户优惠吗？", function() {
				$.operate.post(prefix + "/edit", { "ownerId": ownerId, "useState": 1 });
			})
		}

		/* 启用 */
		function enable(ownerId) {
			$.modal.confirm("确认要冻结此用户优惠吗？", function() {
				$.operate.post(prefix + "/edit", { "ownerId": ownerId, "useState": 3 });
			})
		}
    </script>
</body>
</html>